package com.yuda.operationcenter.mapper;

import java.util.List;
import com.yuda.operationcenter.domain.OperInformation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * 资讯Mapper接口
 *
 * @author wyn
 * @date 2021-04-12
 */
public interface OperInformationMapper
{
    /**
     * 查询资讯
     *
     * @param id 资讯ID
     * @return 资讯
     */
    public OperInformation selectOperInformationById(Long id);

    /**
     * 查询资讯列表
     *
     * @param operInformation 资讯
     * @return 资讯集合
     */
    public List<OperInformation> selectOperInformationList(OperInformation operInformation);

    /**
     * 新增资讯
     *
     * @param operInformation 资讯
     * @return 结果
     */
    public int insertOperInformation(OperInformation operInformation);

    /**
     * 修改资讯
     *
     * @param operInformation 资讯
     * @return 结果
     */
    public int updateOperInformation(OperInformation operInformation);

    /**
     * 删除资讯
     *
     * @param id 资讯ID
     * @return 结果
     */
    public int deleteOperInformationById(Long id);

    /**
     * 批量删除资讯
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteOperInformationByIds(Long[] ids);

    int batchUpdateSellStatus(@Param("ids") Long[] ids,@Param("on_sell") int on_sell);

    int removeImage(Long id);

    int checkIsCanUpdateStatus(@Param("id") Long id);














    //查询order_no字段为0的图文
    public List<OperInformation> selectOperInformation_OrderNo_null(Long[] ids);
    //查询全部order_no不为0的图文（全部上架中的图文）
    public List<OperInformation> selectOperInformation_OrderNo_Notnull();

    //获取未选中的图文
    public List<OperInformation> UnSelected(@Param("ids") Long[] ids);
    //更新未选中图文的排序值
    public int updateUnSelectedOrderNo(@Param("id")long id,@Param("NewOrder")int NewOrder);

    //获取全部图文最大排序值对象
    public Integer MaxOrderNo();


    //根据id把更改order_no
    public int updateOrderNo( @Param("id") long id, @Param("orderNo") int orderNo);

    //根据ids数组查出的图文集合
    public List<OperInformation> selectd(Long[] ids);
    //根据id查出的单个图文
    public OperInformation selectOne(long id);

    //下架改order_no为：0
    public int updateOrder(@Param("id") long id);

    //下架一些咨询后更新其他咨询的order值变为连续，size是被下架咨询数组的长度
    public OperInformation continuousOrder(@Param("id") long id,int size);


    //根据排序值获取对象
    public OperInformation selectedByOrder(@Param("orderNo") int orderNo);

    //使大于参数值得order自动加一
    public int updateOrder1(@Param("orderNo1") int orderNo1,@Param("orderNo2") int orderNo2);
    //使大于参数值得order自动减一
    public int updateOrder2(@Param("orderNo1") int orderNo1,@Param("orderNo2") int orderNo2);


    @Update("update oper_information set order_no = order_no+1 where on_sell=1 and order_no >= #{minOrder} and order_no < #{maxOrder} ")
    void orderAddOne(@Param("minOrder")int minOrder , @Param("maxOrder")int maxOrder);

    int batchUpdateSellStatusAndOrderNo(@Param("id") Long id,@Param("on_sell") int on_sell,@Param("maxOrderNo") int maxOrderNo);

    @Select("select count(1) from oper_information where on_sell = 1 and order_no = #{orderNo}")
    int existOrder(Integer orderNo);

    OperInformation selectedByOrderAndSellEq1(int orderNo);


    boolean checkIsUsed(Long[] ids);


    List<OperInformation> selectByIds(Long[] ids);//通过输入的id数组，查出对应的咨询集合






}
